package br.com.biblioteca.dao;

import br.com.biblioteca.exceptions.InternalServerErrorException;
import java.io.Serializable;
import org.apache.commons.lang.StringUtils;

/**
 *
 * @author João Sávio Ceregatti Longo - joaosavio@gmail.com
 */
public class DAOFacade {
    private static final String USER = "user";
    private static final String BOOK = "book";
    private static final String LOAN = "loan";

    public static DAOService getDAO(Class<? extends Serializable> clazz) {
        String name = clazz.getSimpleName();
        if (StringUtils.equalsIgnoreCase(name, USER)) {
            return DAOFactory.instance(DAOFactory.HIBERNATE).getUserDAO();
        }
        if (StringUtils.equalsIgnoreCase(name, BOOK)) {
            return DAOFactory.instance(DAOFactory.HIBERNATE).getBookDAO();
        }
        if (StringUtils.equalsIgnoreCase(name, LOAN)) {
            return DAOFactory.instance(DAOFactory.HIBERNATE).getLoanDAO();
        }
        throw new InternalServerErrorException("Bad class");
    }
}
